package cn.stylefeng.guns.modular.fi.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.fi.entity.FiHaTempCarAppStand;
import cn.stylefeng.guns.modular.fi.mapper.FiHaTempCarAppStandMapper;
import cn.stylefeng.guns.modular.fi.model.params.FiHaTempCarAppStandParam;
import cn.stylefeng.guns.modular.fi.model.params.FiTempCarAppStandParam;
import cn.stylefeng.guns.modular.fi.model.result.FiHaTempCarAppStandResult;
import  cn.stylefeng.guns.modular.fi.service.FiHaTempCarAppStandService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 临时车超额审批标准 服务实现类
 * </p>
 *
 * @author wp
 * @since 2025-03-10
 */
@Service
public class FiHaTempCarAppStandServiceImpl extends ServiceImpl<FiHaTempCarAppStandMapper, FiHaTempCarAppStand> implements FiHaTempCarAppStandService {

    @Override
    public void add(FiHaTempCarAppStandParam param){
        FiHaTempCarAppStand entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(FiHaTempCarAppStandParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(FiHaTempCarAppStandParam param){
        FiHaTempCarAppStand oldEntity = getOldEntity(param);
        FiHaTempCarAppStand newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public FiHaTempCarAppStandResult findBySpec(FiHaTempCarAppStandParam param){
        return null;
    }

    @Override
    public List<FiHaTempCarAppStandResult> findListBySpec(FiHaTempCarAppStandParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(FiHaTempCarAppStandParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public int isRangeExist(FiHaTempCarAppStandParam param) {
        return this.baseMapper.isRangeExist(param);
    }

    @Override
    public LayuiPageInfo findApproveListPageBySpec(FiHaTempCarAppStandParam fiHaTempCarAppStandParam, String condition) {
        Page pageContext = getPageContext();
        IPage page =this.baseMapper.customApprovePageList(pageContext, fiHaTempCarAppStandParam, condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(FiHaTempCarAppStandParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private FiHaTempCarAppStand getOldEntity(FiHaTempCarAppStandParam param) {
        return this.getById(getKey(param));
    }

    private FiHaTempCarAppStand getEntity(FiHaTempCarAppStandParam param) {
        FiHaTempCarAppStand entity = new FiHaTempCarAppStand();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
